#include "Hut.h"
#include "EntityTypes.h"
#include "Game Factory.h"
#include "GenericKeys.h"
#include "General Utils.hpp"
#include "GameWorld.h"

// Static Variables
int Hut::UnitThreshold = 50000;

// ================================== CTORS ====================================

// Constructor
Hut::Hut(Vector2D position) : Building("hut", position, HutID)
{GenerationLevel = 0;}


// ==============================================================================

// Update
// ---------------------------
// Calls BaseGameEntity's update
// and calls Produce Peasant

void Hut::Update(double time_elapsed)
{
	Building::Update(time_elapsed);

	// Here, I would make a call to Game World to calculate the rate
	// that peasants should be produced

	if(m_iState != Unbuilt)
		ProducePeasant(1.0);
}

void Hut::ProducePeasant(double rate)
{

	if(GenerationLevel >= UnitThreshold)
	{
		// Create a character right infront of the building.
		World->AddEntity(Factory->CreateCharacter(MageID, Pos() + Vector2D(0, BRadius() + 30)));

		GenerationLevel = 0;
	}

	// Simply update the GenerationLevel in accordance to the rate
	GenerationLevel += 100*rate;
}

void Hut::Render()
{
	Building::Render();
	Key->GetFont("Onuava")->drawText(Pos().x  - ClipPlane->GetX(), Pos().y - ClipPlane->GetY(), GetString(GenerationLevel).c_str(), green);
}


